package javabase.base.client10.deep.client3;

import com.google.gson.Gson;
import javabase.base.client10.deep.Address;
import javabase.base.client10.deep.User;
import org.junit.Test;

/**
 * @author chengshuai
 * @date 2021/5/2 13:34
 */
public class Client3 {

    /**
     * Apache Commons Lang序列化
     * 不需要序列化接口和克隆接口
     */
    @Test
    public void f2() {
        Address address = new Address("杭州", "中国");
        User user = new User("大山", address);
        // 使用Gson序列化进行深拷贝
        Gson gson = new Gson();
        User copyUser = gson.fromJson(gson.toJson(user), User.class);
        // 修改源对象的值
        user.getAddress().setCity("深圳");
        // 检查两个对象的值不同
        System.out.println(user.getAddress().getCity());
        System.out.println(copyUser.getAddress().getCity());
    }
}
